#pragma once

#include "common.h"
#include "singleTon.h"

#include <map>
using std::map;

class COpcode2Name
{
	friend class SingleTon<COpcode2Name>;
	typedef map<uint16, string> Opcode2String;

	COpcode2Name() {};

public:

	~COpcode2Name() {}

	inline void AppendOpcode(uint16 opcode, const char* opcodeName, const char* opcodeService)
	{
		ASSERT(m_opcode2Name.count(opcode) == 0);
		m_opcode2Name[opcode] = opcodeName; 
		m_opcodeService[opcode] = opcodeService; 
	}

	inline const string GetOpcodeName(uint16 opcode) const
	{
		Opcode2String::const_iterator it = m_opcode2Name.find(opcode);
		if (it != m_opcode2Name.end())
			return it->second;

		return "NO_REG_OPCODE";
	}

	inline const string GetOpcodeService(uint16 opcode) const
	{
		Opcode2String::const_iterator it = m_opcodeService.find(opcode);
		if (it != m_opcodeService.end())
			return it->second;

		return "NO_REG_OPCODE";
	}
private:

	Opcode2String	m_opcode2Name;
	Opcode2String	m_opcodeService;

};

#define sOpcode							SingleTon<COpcode2Name>::Instance()
#define OPCODE2NAME(opcode)				sOpcode.GetOpcodeName(opcode).c_str()
#define OPCODE2SERVICE(opcode)			sOpcode.GetOpcodeService(opcode).c_str()
#define REG_OPCODE(opcode, opcodeName, opcodeService)	sOpcode.AppendOpcode(opcode, opcodeName, opcodeService)